package com.example.mall.order.interfaces;

import com.example.mall.common.model.Result;
import com.example.mall.common.page.Pageable;
import com.example.mall.order.app.cmd.CreateOrderCmd;
import com.example.mall.order.app.service.OrderAppService;
import com.example.mall.order.app.service.OrderQryService;
import com.example.mall.order.domain.model.Order;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author Mickey
 * @since 2022/4/22
 **/
@RestController
@RequestMapping("/order")
@AllArgsConstructor
public class OrderController {

    private final OrderAppService orderAppService;
    private final OrderQryService orderQryService;

    @PostMapping("/create")
    public Result<Long> create(@RequestBody CreateOrderCmd createOrder) {

        return Result.OK(orderAppService.create(createOrder));
    }

    @GetMapping("/page")
    public Result<Pageable<Order>> page(Pageable<Order> pageable) {
        return Result.OK(orderQryService.page(pageable));
    }
}
